package com.msmall.community.wiki.dao.hibernate;

import java.util.List;

import com.msmall.base.dao.hibernate.BaseDaoHibernate;
import com.msmall.community.klg.model.Article;
import com.msmall.community.wiki.dao.WikiDao;
import com.msmall.community.wiki.model.WikiSegmentArticle;

public class WikiDaoHibernate extends BaseDaoHibernate implements WikiDao{

	/**
	 * 通过字典/百科所属于的分类找出对应的文章
	 */
	public List<Article> getBySegmentid(Long segid) throws Exception{
		String str = "select a from Article a, WikiSegmentArticle sa where a.articleid=sa.articleid and sa.segmentid=? ORDER BY sa.articleid DESC limit 1";
		return getHibernateTemplate().find(str,new Object[]{segid});
	}
	
	public WikiSegmentArticle getByArticleid(Long articleid) throws Exception{
		try{
			String str = "from WikiSegmentArticle sa where sa.articleid=?";
			List list = getHibernateTemplate().find(str,new Object[]{articleid});
			if(list != null && list.size()>0)
				return (WikiSegmentArticle) list.get(0);
		}catch(Exception e){
			throw e;
		}
		return null;
	}
}
